package printer.impl;

import java.util.Set;

import pojo.Customer;
import printer.DataPrinter;

public class DataPrinterImpl implements DataPrinter {

	public StringBuilder print(Set<Customer> customer, String format) {
		if("xml".equals(format)){
			return change2XML(customer);
		}
		else if("line".equals(format)){
			return change2Line(customer);
		}
		return null;
	}
	
	
	public StringBuilder change2XML(Set<Customer> set){
		StringBuilder sb =new StringBuilder("");
		sb.append("<Customers>\r\n");
		for(Customer c:set){
			sb.append("\r\n");
			sb.append("  <Customer id=\""+c.getId()+"\">\r\n");
			sb.append("\t<name>"+c.getName()+"<name>\r\n");
			sb.append("\t<birthday>"+c.getBirthday()+"<birthday>\r\n");
			sb.append("\t<sex>"+c.getSex()+"<sex>\r\n");
			sb.append("\t<email>"+c.getEmail()+"<email>\r\n");
			sb.append("  </Customer>\r\n");
			sb.append("\r\n");
		}
		sb.append("</Customers>\r\n");
		
		return sb;
	}
	
	
	public StringBuilder change2Line(Set<Customer> set){
		StringBuilder sb =new StringBuilder("");
		for(Customer c:set){
			sb.append("id: "+c.getId()+"\tname: "+c.getName()+"\temail: "+c.getEmail()+"\tsex: "+c.getSex()+"\tbirthday"+c.getBirthday()+"\r\n");
		}
		
		return sb;
	}
	

}
